package roborl;

import java.io.Serializable;
import java.util.Vector;

public abstract class ValueApproximate  implements Serializable{
	public abstract void updateValue(RobotState robotState, Action action,
			double newValue);

	public abstract double getValue(RobotState robotState, Action action);

	Vector<Action> actionSet;

	public ValueApproximate(Vector<Action> actionSet) {
		this.actionSet = actionSet;
	}

	public Double getBestValue(RobotState state) {
		double best = 0;
		Action ba = null;
		for (Action action : actionSet) {
			if (ba == null || getValue(state, action) > best) {
				best = getValue(state, action);
				ba = action;
			}
		}
		return best;
	}

	public Action getBestAction(RobotState state) {
		return getBestAction(state, null);
	}

	public Action getBestAction(RobotState state, Vector<Action> as) {
		double best = 0;
		Action ba = null;
		System.out.print(state+" --> ");
		for (Action action : (as==null?this.actionSet:as)) {
			System.out.print(action + " " + getValue(state, action)+" <> ");
			if (ba == null || getValue(state, action) > best) {
				best = getValue(state, action);
				ba = action;
			}
		}
		System.out.println();
		return ba;
	}
}
